import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @author ypz
 * @date 2021/9/10 13:54
 */
public class StreamTest2 {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("hello","","world","hello","","zhang","san","lining","sam","baby");
        //统计非空字符串
        long count = list.stream().filter(e -> !e.isEmpty()).count();
        System.out.println("统计非空字符串-->"+count);
        //字符串长度等于3的数量
        long count1 = list.stream().filter(e -> e.length() == 3).count();
        System.out.println("统计长度等于3的字符串数量-->"+count1);
        //根据某种条件重新筛选出list集合
        List<String> collect = list.stream().filter(e -> !e.isEmpty()).collect(Collectors.toList());
        System.out.println("不为空的字符串列表-->"+collect);
        //合并字符串
        String collect1 = list.stream().filter(e -> !e.isEmpty()).collect(Collectors.joining(","));
        System.out.println("合并字符串-->"+collect1);
        //去重
        List<String> collect2 = list.stream().distinct().collect(Collectors.toList());
        System.out.println("去重-->："+collect2);
        //排序
        /*System.out.println("排序：");
        Random random = new Random();
        random.ints().limit(10).sorted().forEach(System.out::println);*/
        //并行处理
        long count2 = list.parallelStream().filter(e -> e.isEmpty()).count();
        System.out.println("空字符串并行统计-->"+count2);
    }
}
